<template>
  <div>
    <tableComponents :pagination="{ currentPage, pageSize, total: list.all_num }" @handleCurrentChange="handleCurrentChange"
        @handleSizeChange="handleSizeChange" @sendUserSearch="receive_search" :searchData="userSearchData" :isHaveExport="false" :isHaveAdd="false"
        @toAdd="add_data" :isShow="true">
      <template v-slot:table>
        <el-table ref="multipleTable" :data="list.data" stripe v-loading="loading" header-row-class-name="head_color" tooltip-effect="dark"
            style="width: 99.8%" @selection-change="handleSelectionChange">
          <el-table-column type="selection" class="tc" width="35"></el-table-column>
          <el-table-column label="用户名称" min-width="120">
            <template slot-scope="scope">
              <div class="user_table">
                <span>发布人用户名：</span>
                <small>{{ scope.row.s_username || "----" }}</small>
                <br />
                <span>发布人昵称：</span>
                <small>{{ scope.row.s_nickname || "----" }}</small>
                <br />
                <span>接收人用户名：</span>
                <small>{{ scope.row.username || "----" }}</small>
                <br />
                <span>接收人昵称：</span>
                <small>{{ scope.row.nickname || "----" }}</small>
                <br />
              </div>
            </template>
          </el-table-column>
          <el-table-column label="任务信息" min-width="120">
            <template slot-scope="scope">
              <div class="user_table">
                <span>任务单号：</span>
                <small>{{ scope.row.t_oid || "----" }}</small>
                <br />
                <span>任务标题：</span>
                <small>{{ scope.row.title || "----" }}</small>
                <br />
                <span>任务备注：</span>
                <small>{{ scope.row.remark || "----" }}</small>
                <br />
              </div>
            </template>
          </el-table-column>
          <el-table-column label="订单信息" min-width="120">
            <template slot-scope="scope">
              <div class="user_table">
                <span>订单号：</span>
                <small>{{ scope.row.oid || "----" }}</small>
                <br />
                <span>订单状态：</span>
                <small>{{ scope.row.status || "----" }}</small>
                <br />
                <span>限时完成：</span>
                <small>{{ scope.row.carry }}</small>
                <br />
                <span>限时审核：</span>
                <small>{{ scope.row.audit }}</small>
                <br />
                <span>单价：</span>
                <small>{{ scope.row.price }}</small>
                <br />
                <span>交付信息：</span>
                <small>{{ scope.row.content || "----" }}</small>
                <br />
                <div>
                  <span>拒绝原因：</span>
                  <small>{{ scope.row.denial_reason || "----" }}</small>
                </div>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="时间信息" min-width="120">
            <template slot-scope="scope">
              <div class="user_table">
                <span>关闭时间：</span>
                <small>{{ scope.row.end_time | getTimeFormat }}</small>
                <br />
                <span>交付时间：</span>
                <small>{{ scope.row.complete_time | getTimeFormat }}</small>
                <br />
                <span>审核时间：</span>
                <small>{{ scope.row.check_time | getTimeFormat }}</small>
                <br />
                <span>更新时间：</span>
                <small>{{ scope.row.update_time | getTimeFormat }}</small>
                <br />
                <span>添加时间：</span>
                <small>{{ scope.row.created_time | getTimeFormat }}</small>
                <br />
              </div>
            </template>
          </el-table-column>
          <el-table-column width="300" label="操作">
            <template slot-scope="scope">
              <el-button size="mini" v-show="
                  scope.row.status == '待审核' || scope.row.status == '已拒绝'
                " @click="toagree(scope.row.id)" type="success">通过审核</el-button>
              <el-button size="mini" @click="showimg(scope.row.piclink)" type="success" :disabled="scope.row.piclink == '' ? true : false">查看
              </el-button>
              <el-button size="mini" @click="delOne(scope.row.id)" type="danger">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
      </template>
      <template v-slot:footerLeft>
        <a class="aBtn aBtn_1 aBtn_lan2" @click="delSelection()">删除</a>
      </template>
    </tableComponents>
    <el-dialog :close-on-click-modal="false" title="任务步骤" :append-to-body="true" width="1200px" :visible.sync="dialogeditVisible">
      <div style="width:100%;display:flex;justify-content: flex-start">
        <el-popover placement="right" title trigger="hover" v-for="(img, i) in piclink" :key="i"
            style="width:200px;height:200px;overflow:hidden;display: flex;justify-content: center; align-items: center;overflow: hidden;margin-right:15px">
          <img :src="$fnc.getImgUrl(img)" style="widht:100%" alt />
          <img slot="reference" :src="$fnc.getImgUrl(img)" :alt="img" style="width:100%" />
        </el-popover>
      </div>
    </el-dialog>
    <keep-alive>
      <component :is="current" :show="shows" :isAll="true" showType="list" @sendShop="getSend" @isshow="getShow"></component>
    </keep-alive>
  </div>
</template>
<script>
import uploadpic from "@/components/page/pic/up_pic"; //上传图片
import { doTaskList } from "@/assets/js/searchData/searchData"; //引入搜索的数据
import xzShop from "@/components/currency/xz_shop.vue";
export default {
  data () {
    return {
      piclink: [],
      shows: true,
      current: "",
      shopinfo: {
        title: ""
      },
      userSearchData: doTaskList,
      dialogeditVisible: false,
      // 输入值库
      edit_form: {
        piclink: ""
      },
      // editMsg: {},
      createTime: [],
      formVideo: {
        uid: "",
        uri: "",
        is_recommend: 0,
        // title: "",
        duration: "",
        start_time: "",
        stop_time: ""
      },
      dialogaddVisible: false,
      playurl: "",
      is_edit: false,
      dialogFormVisible: false,
      live_single: {
        piclink: ""
      },
      current: "",
      loading: false,
      list: [],
      allPage: 0,
      allNum: 0,
      pageSize: 10,
      currentPage: 1,
      searchAll: {},
      row: {},
      showCity: true,
      // 头像
      dialogImageUrl: "",
      dialogVisible: false,
      // 分类
      edmsgs: {},
      siteid: "",
      siteobj: {},
      changePriceFlag: false,
      nowPlace: "",
      timeMsg: [],
      wanna_del: "",
      multipleSelection: [] //多选框玄宗的值
    };
  },
  components: {
    uploadpic,
    xzShop
  },
  created () {
    this.getDoTaskList();
  },
  methods: {
    showimg (piclink) {
      try {
        this.piclink = piclink.split("@");
        this.dialogeditVisible = true;
      } catch (error) {
        this.piclink = [];
      }
    },
    sorta (a, b) {
      return b - a;
    },
    formatMoney (value) {
      return value.split(".")[0] + "." + value.split(".")[1].slice(0, 2);
    },
    changePrice (value) {
      this.changePriceFlag = true;
      this.nowPlace = value.title;
      this.timeMsg = value.time_price;
      console.log(value);
    },
    // 添加
    add () {
      let params = this.edit_form;
      console.log("comming");
      console.log(this.edit_form);
      this.$api.getTask.addTaskCate(params).then(res => {
        if (res.data.code == 200) {
          this.$swal("添加成功！", "任务添加成功添加", "success");
          this.getCate();
        } else {
          this.$swal("出错了！", res.data.result, "error");
        }
        this.dialogFormVisible = false;
      });
    },
    // 通过审核
    toagree (id) {
      console.log(id);
      let params = {};
      params.id = id;
      this.$api.getTask.agreeTask(params).then(res => {
        if (res.data.code == 200) {
          this.$swal("审核通过！", "该任务已成功通过了审核", "success");
        } else {
          this.$swal("出错了！", res.data.result, "error");
        }
        this.getDoTaskList();
      });
    },
    // 编辑
    toedit (item) {
      this.dialogeditVisible = true;
      this.edmsgs = item;
    },
    // 修改
    edit () {
      console.log(this.edmsgs);
      let params = this.edmsgs;
      this.$api.getTask.editTaskCate(params).then(res => {
        if (res.data.code == 200) {
          this.$swal("添加成功！", "任务添加成功添加", "success");
          this.getCate();
        } else {
          this.$swal("出错了！", res.data.result, "error");
        }
        this.dialogeditVisible = false;
      });
    },
    // 多选框赋值
    handleSelectionChange (val) {
      //多选框赋值
      console.log(val);
      this.multipleSelection = val;
    },
    // 删除
    delOne (id) {
      console.log(id);
      let params = {};
      params.id_str = id;
      // console.log(params)
      this.$api.getTask.delDoList(params).then(res => {
        if (res.data.code == 200) {
          this.$swal("添加成功！", "任务添加成功添加", "success");
        } else {
          this.$swal("出错了！", res.data.result, "error");
        }
        this.getDoTaskList();
      });
    },
    // 批量删除
    delSelection () {
      let str = "";
      if (this.multipleSelection.length <= 0) {
        this.$message.error("未选择批量删除");
      } else {
        for (const iterator of this.multipleSelection) {
          str += iterator.id + "@";
        }
        str = str.slice(0, -1); //将最后的@去掉
        console.log(str);
        this.$swal({
          title: "您确定要删除这些信息吗",
          text: "删除后将无法恢复，请谨慎操作！",
          type: "warning",
          showCancelButton: true,
          confirmButtonColor: "#DD6B55",
          confirmButtonText: "是的，我要删除",
          cancelButtonText: "容我三思"
        }).then(willDelete => {
          if (willDelete.value) {
            let data = { id_str: str };
            this.$api.getTask.delDoList(data).then(res => {
              if (res.data.code == 200) {
                this.$swal("删除成功！", "您已经删除了这些信息。", "success");
                this.getDoTaskList();
              } else {
                this.$swal("删除失败！", res.data.result, "error");
              }
            });
          }
        });
      }
    },
    getList () {
      this.$api.getBasketBalls
        .getSiteInformation({ page: 1, page_size: 50 })
        .then(res => {
          this.$store.commit("setallbasket", res.data.result.data);
        });
    },
    getDoTaskList (data) {
      // console.log("he;;o789");
      var params = data || {};
      if (this.$route.query.id) {
        params.tid = this.$route.query.id;
      }

      this.$api.getTask.getDoList(params).then(res => {
        if (res.data.code == 200) {
          this.list = res.data.result;
        }
      });
    },

    format (value) {
      let time = new Date(parseInt(value) * 1000);
      // console.log(555,time)
      time =
        time.toLocaleDateString().replace(/\//g, "-") +
        " " +
        time.toTimeString().substr(0, 8);
      return time;
    },
    xzshop (str) {
      if (str == "xzShop") {
        if (
          this.$store.state.shopSlist == "" ||
          this.$store.state.shopSlist.page != 1
        ) {
          this.$store.dispatch("getShopsAll", { page: 1, page_size: 10 });
        }
      }
      this.current = str;
      this.shows = true;
    },
    getShow (val) {
      this.shows = val;
    },
    getSend (row) {
      console.log(row);
      if (this.current == "xzShop") {
        console.log(row);
        this.shopinfo = row;
        this.formVideo.pid = row.id;
      }
    },

    editbtn (item) {
      this.edit_form = item;
      this.dialogeditVisible = true;
    },

    addbtn () { },

    rev_send_url (val) {
      this.formVideo.uri = val.url;
    },
    add_data () {
      this.dialogFormVisible = true;
    },
    change_recomment (val, row, type) {
      var params = {};
      params.id = row.id;
      if (type == "recomment") {
        params.is_recommend = val;
      } else {
        params.is_check = val;
      }
      this.$api.getPage.edit_reply_isrecommend(params).then(res => {
        if (res.data.code == 200) {
          this.$fnc.alertSuccess(res.data.result);
        } else {
          this.$fnc.alertError(res.data.result);
        }
      });
    },
    dia_close () {
      this.playurl = "";
      var x = document.getElementById("videobox");
      x.load();
    },
    showvideo (info) {
      this.dialogFormVisible = true;
      if (info.uri.indexOf("http") < 0) {
        this.playurl =
          "https://inexweb.oss-cn-shenzhen.aliyuncs.com/" + info.uri;
      } else {
        this.playurl = info.uri;
      }
      this.$nextTick(() => {
        var x = document.getElementById("videobox");
        x.load();
      });
    },
    receive_search (obj) {
      // console.log(obj)
      this.searchAll = obj;
      // this.getNewsAll(obj);
      this.getDoTaskList(obj);
    },

    handleSizeChange (val) {
      var params = this.searchAll;
      params.page = "";
      params.page_size = val;
      this.getDoTaskList(params);
      this.pageSize = val;
    },
    handleCurrentChange (val) {
      this.currentPage = val;
      var params = this.searchAll;
      params.page = val;
      params.page_size = this.pageSize;
      this.getDoTaskList(params);
    },

    reload () {
      this.getDoTaskList(this.searchAll);
    },
    // 添加图片
    handleRemove (file, fileList) {
      console.log(file, fileList);
    },
    handlePictureCardPreview (file) {
      this.dialogImageUrl = file.url;
      this.dialogVisible = true;
    },
    // 删除
    beforeCreate () { }
  }
};
</script>

<style lang="less" scoped>
.myblank button {
  margin: 5px 5px 0 0;
}

.place {
  margin: 5px 0;
}
.is_item {
  display: flex;
  align-items: flex-end;
  .types {
    div {
      width: 200px;
      margin-right: 10px;
    }
    .input {
      margin: 5px 0px;
    }
    display: flex;
  }
  .btn_edit {
    height: 40px;
    margin-left: 10px;
    margin-bottom: 5px;
  }
}
.know_btn {
  width: 100%;
  display: flex !important;
  justify-content: flex-end !important;
}
</style>
